package com.dragee.modules.officialWebsite.controller;

import com.dragee.common.R;
import com.dragee.modules.officialWebsite.entity.GwTitleDiscriptionEntity;
import com.dragee.modules.officialWebsite.service.GwTitleDiscriptionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;



/**
 * 标题和描述维护
 *
 * @author tc
 * @email tc@mail.com
 * @date 2023-07-15 21:51:30
 */
@RestController
@RequestMapping("officialWebsite/gwtitlediscription")
@Api(tags = "标题和描述维护")
public class GwTitleDiscriptionController {
    @Autowired
    private GwTitleDiscriptionService gwTitleDiscriptionService;
//
//    /**
//     * 列表
//     */
//    @GetMapping("list")
//    @ApiOperation("标题和描述维护列表")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = gwTitleDiscriptionService.queryPage(params);
//        return R.ok().put("data", page);
//    }

    /**
     * 数据
     */
    @GetMapping("data")
    @ApiOperation("标题和描述维护数据")
    public R data(){
        List<GwTitleDiscriptionEntity> datas = gwTitleDiscriptionService.list();
        GwTitleDiscriptionEntity data = datas.get(0);
        if (data == null) {
            return R.ok().put("title", "").put("discription", "");
        }
        return R.ok().put("title", data.getTitle()).put("discription", data.getDiscription());
    }




    /**
     * 信息
     */
    @GetMapping("{id}")
    @ApiOperation("标题和描述维护信息")
    public R info(@PathVariable("id") Long id){
		GwTitleDiscriptionEntity gwTitleDiscription = gwTitleDiscriptionService.getById(id);
        return R.ok().put("data", gwTitleDiscription);
    }

    /**
     * 保存
     */
    @PostMapping("saveOrUpdate")
    @ApiOperation("保存或修改标题和描述维护")
    public R saveOrUpdate(@RequestBody GwTitleDiscriptionEntity gwTitleDiscription){
        gwTitleDiscriptionService.saveOrUpdate(gwTitleDiscription);
        return R.ok();
    }


    /**
     * 删除
     */
    @GetMapping("delete-by-id")
    @ApiOperation("标题和描述维护删除")
    public R delete( String id){
		gwTitleDiscriptionService.removeById(Long.parseLong(id));
        return R.ok();
    }

    @GetMapping("delete-by-ids")
    @ApiOperation("标题和描述维护批量删除")
    public R deletes(String ids){
        String[] idArr = ids.split(",");
        Arrays.stream(idArr).forEach(id -> gwTitleDiscriptionService.removeById(Long.parseLong(id)));
        return R.ok();
    }



}
